import kk.dao.*;
import kk.domain.*;
import kk.utils.PasswordUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Date;
import java.util.List;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class testDao {
    @Autowired
    private ProductDao productDao;

    @Autowired
    private OrdersDao ordersDao;

    @Autowired
    private UserDao userDao;

    @Autowired
    private RoleDao roleDao;

    @Autowired
    private SysLogDao sysLogDao;
    @Test
    public void test() throws Exception {
        List<Orders> all = ordersDao.findAll();
        for (Orders orders : all) {
//            Product product = orders.getProduct();
            System.out.println(orders);
        }
    }


    @Test
    public void test2() throws Exception {
        List<UserInfo> userInfoList = userDao.findAll();
        System.out.println(userInfoList);
    }


    @Test
    public void test3() throws Exception{
        Role role = roleDao.findById(2);
        System.out.println(role);
    }

    @Test
    public void test4(){
        String s = PasswordUtils.EncodePassword("123");
        System.out.println(s);
    }

    @Test
    public void test5() throws Exception {
        List<SysLog> sysLogs = sysLogDao.findAll();
        for (SysLog sysLog : sysLogs) {

        }
    }

    @Test
    public void test6() throws Exception{
        Orders orders=new Orders();
        orders.setOrderNum("testorder");
        orders.setOrderTime(new Date());
        orders.setPeopleCount(20);
        orders.setOrderDesc("testtest");
        orders.setPayType(1);
        orders.setOrderStatus(1);
        orders.setProductId(1);
        orders.setMemberId(4);
        ordersDao.add(orders);
    }

    @Test
    public void test7() throws Exception{
        List<Product> list = productDao.findByName("%五日游%");
        for (Product product : list) {
            System.out.println(product);
        }
    }
}
